package com.bb.services.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;

import com.bb.dao.HouseDao;
import com.bb.pojo.House;
import com.bb.service.HouseService;
import com.bb.util.GetSqlSessionUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

public class HouseServiceImpl implements HouseService{

	@Override
	public int addHouse(House house) {//新增租房
		SqlSession sqlSession = new GetSqlSessionUtil().getSqlSession(); 
		HouseDao mapper = sqlSession.getMapper(HouseDao.class);
		int insertintoHouse = mapper.insertintoHouse(house);
		sqlSession.commit();
		return insertintoHouse;
	}

	@Override
	public Map selectHouse(Map map) {
		// TODO Auto-generated method stub
		SqlSession sqlSession = new GetSqlSessionUtil().getSqlSession(); 
		HouseDao mapper = sqlSession.getMapper(HouseDao.class); 			
	 	System.out.println("今如方法中"+map.get("currentPage"));
	 	int curr = (int) map.get("currentPage");
	 	Page<PageInfo> startPage = PageHelper.startPage(curr, 5);
	 	List<House> selectAllHouse = mapper.selectAllHouse(map);
	 	//PageInfo pageInfo = new PageInfo(selectAllHouse);
	 	/*System.out.println("helper当前的页数"+startPage.getPageNum());
	 	System.out.println("helper得到的页数"+startPage.getPages());
	 	System.out.println("helper得到的页数"+startPage.getTotal());*/
	 	/*System.out.println("helper当前页数"+pageInfo.getPageNum());
	 	System.out.println("helper总页数"+pageInfo.getPages());
	 	System.out.println("helper总数据"+pageInfo.getList());*/
	 	Map mapp = new HashMap();
	 	mapp.put("currentPage", startPage.getPageNum());//当前页
	 	mapp.put("totalPage", startPage.getPages());//总页数
	 	mapp.put("list", selectAllHouse);
	 	return mapp;
	}
	/*public static void main(String[] args){
		HouseServiceImpl HouseServiceImpl = new HouseServiceImpl();
		HouseServiceImpl.selectHouse(null);
	}*/
	
}
